package xna.android;

import android.graphics.Bitmap;
import android.util.Log;

public class Ball implements GameObjects{

	private SpriteAnimated spriteBall;
	private int width;
	private int height;
	private boolean inGame;
	private int speedX;
	private int speedY;
	private String color;

	public Ball(SpriteAnimated spriteBall, int speed)
	{
		this.spriteBall = spriteBall;
		this.width = spriteBall.getSourceRect().width();
		this.height = spriteBall.getSourceRect().height();
		this.inGame = false;
		this.speedX = speed;
		this.speedY = -speed;
		this.color = "cyan";
	}

	public SpriteAnimated getSpriteBall() {
		return spriteBall;
	}

	public void setSpriteBall(SpriteAnimated spriteBall) {
		this.spriteBall = spriteBall;
	}

	public int getWidth() {
		return this.width;
	}

	public int getHeight() {
		return this.height;
	}

	public boolean isInGame() {
		return inGame;
	}

	public void setInGame(boolean inGame) {
		this.inGame = inGame;
	}

	public int getSpeedX() {
		return speedX;
	}

	public void setSpeedX(int speedX) {
		this.speedX = speedX;
	}

	public int getSpeedY() {
		return speedY;
	}

	public void setSpeedY(int speedY) {
		this.speedY = speedY;
	}

	public int getX() {
		return spriteBall.getX();
	}

	public void setX(int x) {
		spriteBall.setX(x);
	}

	public int getY() {
		return spriteBall.getY();
	}

	public void setY(int y) {
		spriteBall.setY(y);		
	}
	
	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}
	
	public void addSpeed(int velX, int velY) {
		if (this.speedX > 0) {
			this.speedX += velX; 
		} else {
			this.speedX -= velX;
		}
		
		if (this.speedY > 0) {
			this.speedY += velY;
		} else {
			this.speedY -= velY;
		}
	}

	public void update()
	{		
		if(inGame)
		{
			spriteBall.setX(spriteBall.getX()+speedX);
			spriteBall.setY(spriteBall.getY()+speedY);
		}
		
		switch (spriteBall.getCurrentFrame()) {
			case 0:
				color = "cyan";
				break;
			case 1:
				color = "magenta";
				break;
			case 2:
				color = "yellow";
				break;
			case 3:
				color = "green";
				break;
			default:
				break;
		}
		
		//Log.i(this.toString(), color);
		
		spriteBall.update(System.currentTimeMillis());
	}
}
